package com.goldsprite.contourextraction.core;

public class ImageUtils {

	public static int[][] reverseY(int[][] image) {
		int height = image.length;
		int width = image[0].length;
		int[][] result = new int[height][width];
		for (int y = 0; y < height; y++) {
			for (int x = 0; x < width; x++) {
				result[y][x] = image[height-1-y][x];
			}
		}
		return result;
	}
	/**
	 * 创建六角星测试图像
	 */
	public static int[][] createHexagonStarImage() {
		return reverseY(new int[][]{
			{1, 0, 0, 0, 1, 0, 0, 0, 1},
			{0, 1, 0, 1, 1, 1, 0, 1, 0},
			{0, 0, 1, 1, 1, 1, 1, 0, 0},
			{0, 1, 1, 1, 1, 1, 1, 1, 0},
			{1, 1, 1, 1, 1, 1, 1, 1, 1},
			{0, 1, 1, 1, 1, 1, 1, 1, 0},
			{0, 0, 1, 1, 1, 1, 1, 0, 0},
			{0, 1, 0, 1, 1, 1, 0, 1, 0},
			{1, 0, 0, 0, 1, 0, 0, 0, 1}
		});
	}

	/**
	 * 创建带内部空洞的六角星测试图像
	 */
	public static int[][] createHexagonStarWithHole() {
		return reverseY(new int[][]{
			{1, 0, 0, 0, 1, 0, 0, 0, 1},
			{0, 1, 0, 1, 1, 1, 0, 1, 0},
			{0, 0, 1, 1, 0, 1, 1, 0, 0},
			{0, 1, 1, 0, 0, 0, 1, 1, 0},
			{1, 1, 0, 0, 0, 0, 0, 1, 1},
			{0, 1, 1, 0, 0, 0, 1, 1, 0},
			{0, 0, 1, 1, 0, 1, 1, 0, 0},
			{0, 1, 0, 1, 1, 1, 0, 1, 0},
			{1, 0, 0, 0, 1, 0, 0, 0, 1}
		});
	}

	/**
	 * 创建矩形测试图像
	 */
	public static int[][] createRectangleImage() {
		return reverseY(new int[][]{
			{0, 0, 0, 0, 0, 0, 0, 0, 0},
			{0, 1, 1, 1, 1, 1, 1, 1, 0},
			{0, 1, 1, 1, 1, 1, 1, 1, 0},
			{0, 1, 1, 1, 1, 1, 1, 1, 0},
			{0, 1, 1, 1, 1, 1, 1, 1, 0},
			{0, 1, 1, 1, 1, 1, 1, 1, 0},
			{0, 1, 1, 1, 1, 1, 1, 1, 0},
			{0, 1, 1, 1, 1, 1, 1, 1, 0},
			{0, 0, 0, 0, 0, 0, 0, 0, 0}
		});
	}

	/**
	 * 创建圆角矩形测试图像
	 */
	public static int[][] createRoundRectangleImage() {
		return reverseY(new int[][]{
			{0, 0, 1, 1, 1, 1, 1, 0, 0},
			{0, 1, 1, 1, 1, 1, 1, 1, 0},
			{1, 1, 1, 1, 1, 1, 1, 1, 1},
			{1, 1, 1, 1, 1, 1, 1, 1, 1},
			{1, 1, 1, 1, 1, 1, 1, 1, 1},
			{1, 1, 1, 1, 1, 1, 1, 1, 1},
			{1, 1, 1, 1, 1, 1, 1, 1, 1},
			{0, 1, 1, 1, 1, 1, 1, 1, 0},
			{0, 0, 1, 1, 1, 1, 1, 0, 0}
		});
	}

	/**
	 * 创建简单的L形测试图像（用于验证链码）
	 */
	public static int[][] createLShapeImage() {
		return reverseY(new int[][]{
			{0, 0, 0, 0, 0},
			{0, 1, 1, 0, 0},
			{0, 1, 0, 0, 0},
			{0, 1, 0, 0, 0},
			{0, 1, 1, 1, 0},
			{0, 0, 0, 0, 0}
		});
	}

	/**
	 * 创建三角形测试图像
	 */
	public static int[][] createTriangleImage() {
		return reverseY(new int[][]{
			{0, 0, 0, 0, 0, 0, 0},
			{0, 0, 0, 1, 0, 0, 0},
			{0, 0, 1, 1, 1, 0, 0},
			{0, 1, 1, 1, 1, 1, 0},
			{1, 1, 1, 1, 1, 1, 1},
			{0, 0, 0, 0, 0, 0, 0}
		});
	}

	public static int[][] createTestImage() {
		return reverseY(new int[][]{
			{0, 0, 0, 0, 0, 1, 0},
			{0, 0, 1, 1, 1, 0, 0},
			{0, 0, 1, 1, 0, 0, 0},
			{0, 0, 1, 1, 0, 0, 0},
			{0, 0, 0, 0, 1, 0, 0},
			{0, 0, 1, 1, 1, 1, 0},
			{0, 0, 0, 0, 0, 0, 0}
		});
	}
}
